window.onload = function () {
    serviceProviders();
}

function serviceProviders() {
    var providers = new Array();
    providers.push("Way2SMS");
    providers.push("FullOnSMS");
    providers.push("160By2");
    providers.push("Site2SMS");
    providers.push("IndyaRocks");
    providers.push("SMSAbc");
    providers.push("SmsFI");
    providers.push("Ultoo");
    providers.push("SmsSpark");
    providers.push("FreeSMS8");
    providers.push("SMS440");
    providers.push("BhokaliSMS");
    

    var html = "<select class=\"sel\" id=\"ddl\">";
    for (i = 0; i < providers.length; i++) {
        html = html + "<OPTION value=\"" + providers[i] + "\">" + providers[i] + "</OPTION>";
    }
    html = html + "</select>";
    if (document.getElementById("select") != null)
        document.getElementById("select").innerHTML = html;
}

function XHConn() {
    var xmlhttp, bComplete = false;
    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
        try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) {
            try { xmlhttp = new XMLHttpRequest(); }
            catch (e) { xmlhttp = false; }
        }
    }
    if (!xmlhttp) return null;
    this.connect = function (sURL, sMethod, sVars, fnDone) {
        if (!xmlhttp) return false;
        bComplete = false;
        sMethod = sMethod.toUpperCase();

        try {
            if (sMethod == "GET") {
                xmlhttp.open(sMethod, sURL + "?" + sVars, true);
                sVars = "";
            }
            else {
                xmlhttp.open(sMethod, sURL, true);
                xmlhttp.setRequestHeader("Method", "POST " + sURL + " HTTP/1.1");
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && !bComplete) {
                    bComplete = true;
                    fnDone(xmlhttp.responseText);
                }
            };
            xmlhttp.send(sVars);
        }
        catch (z) { return false; }
        return true;
    };
    return this;
}

function validate() {

    if ($$("txtUid") == "Username") {
        msg("Invalid Userid");
        return false;
    }
    if ($$("txtPwd") == "Password") {
        msg("Invalid Password");
        return false;
    }
    if ($$("txtPhoneNo") == "Send To Mobile No") {
        msg("Invalid Mobile No");
        return false;
    }
    if (document.getElementById("cbFuture").checked) {
        if ($$("txtDate") == "ddmmyyyy") {
            msg("Invalid Date / Time Specified");
            return false;
        }
        if ($$("txtTime") == "hhmm") {
            msg("Invalid Date / Time Specified");
            return false;
        }
    }
    return true;

}
function msg(value) {
    document.getElementById("result").innerHTML = value;
}
function $$(ID) {
    return document.getElementById(ID).value;
}

function send() {
    if (validate()) {

        document.getElementById("result").innerHTML = "<img src='https://facebookstatusgenerator2.googlecode.com/svn/trunk/ajax-loader.gif' />";
        var ddl = document.getElementById("ddl");
        var ddlText = ddl.options[ddl.selectedIndex].text;
        var msg = encodeURIComponent($$("txtMsg"));

        var urlString = "&codes=1&uid=" + $$("txtUid") + "&pwd=" + $$("txtPwd") + "&phone=" + $$("txtPhoneNo") + "&msg=" + msg + "&provider=" + ddlText + "&ts=" + myTimestamp();
        if (document.getElementById("cbFuture").checked) {
            urlString = urlString + "&future=1&date=" + $$("txtDate") + "&time=" + $$("txtTime");
        }


        var myConn = new XHConn();
        if (!myConn) fnWhenDone("XMLHTTP not available. Try a newer/better browser.");
        myConn.connect("http://ubaid.tk/sms/sms.aspx", "GET", urlString, fnWhenDone);


    }
    //showAdBlocker();
	openPopup();
}

fnWhenDone = function (response) {
    document.getElementById("result").innerHTML = response;
};

													

function myTimestamp() {
    tstmp = new Date();
    return tstmp.getTime();
}

function fnFocus(obj) {
    if (obj.value == obj.defaultValue) {
        if (obj.value == "Password") {
            obj.type = "password";
        }
        obj.value = '';
    };
}

function fnBlur(obj) {
    if (obj.value == '') {
        obj.value = obj.defaultValue;
        obj.type = "text";
    }
}

function count() {
    document.getElementById("countdown").innerHTML = "<font size='1'>" + $$("txtMsg").length + " chars used.</font>";
}

function future() {
    var chek = document.getElementById("cbFuture").checked;

    if (chek)
        document.getElementById("futureTr").style.display = "";
    else
        document.getElementById("futureTr").style.display = "none";
}

